<template>
  <div class="contrainer">
    <el-header style="height: 10vh">
      <span class="logo">
        <img src="../../assets/logo.png" alt="" />
      </span>
      <span>
           <div class="search">
      <input type="text" class="searchTerm" placeholder="你想找什么影视?" v-model="searchText">
      <button type="submit" class="searchButton" @click.prevent="search">
        <i class="fa fa-search"></i>
     </button>
   </div>
      </span>
      <span :class="isLogin ? 'Logined' : 'tool'">
        <i
          class="el-icon-user-solid"
          style="height: 30px; line-height: 30px"
        ></i
        ><a href="javascript:void(0);" @click="toLogin">登陆</a>&nbsp;&nbsp;/<a
          href="javascript:void(0);"
          @click="toRegister"
          >注册</a
        ></span
      >
      <span :class="isLogin ? 'myself' : 'no'">
        <router-link to="/third" style="text-decoration: none"
          ><a>历史记录</a></router-link
        >
      </span>
      <!-- <span :class="isLogin ? 'myself' : 'no'">
        <router-link to="/my" style="text-decoration: none">
          <img
            src="https://img2.baidu.com/it/u=4289178445,1310320032&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
            alt=""
            style="width: 50px; height: 50px; border-radius: 50%"
          />
        </router-link>
      </span> -->
      <span :class="isLogin ? 'myself' : 'no'">
        <a href="javascript:void(0);" @click="quit">退出</a>
      </span>
    </el-header>
    <div class="nav-context">
      <router-link to="/home" style="text-decoration: none" tabindex="1"
      active-class='ative'
        ><a>首页</a></router-link
      >
      <router-link
        to="/detail/1"
        style="margin-left: 20px; text-decoration: none"
        tabindex="2"
        active-class='ative'
        ><a>分类</a></router-link
      >
    </div>
    <div class="main">
      <transition name="el-fade-in">
        <router-view />
      </transition>
    </div>
  </div>
</template>

<script>
import {getUserInfo} from '../../api/user';
export default {
  name: "Home",
  data() {
    return {
      isLogin: false,
      searchText: "",
    };
  },
  created(){
    getUserInfo().then(res=>{
      console.log(res);
    })
  },
  mounted() {
    this.land();
  },
  methods: {

    search() {
      if(this.searchText){
        this.$router.push({
        path: "/first",
        query: {
          searchText: this.searchText,
        },
      });
      }else{
        this.$message.info('请输入搜索影视作品名称！')
      }
    },
    land() {
      if (sessionStorage.getItem("phoneNum") && localStorage.getItem("u_id")) {
        this.isLogin = true;
      } else {
        this.isLogin = false;
      }
    },
    quit() {
       this.$confirm('确认退出登录?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
                localStorage.removeItem("u_id");
      localStorage.removeItem("token");
      sessionStorage.removeItem("phoneNum");
      this.land();
          this.$message({
            type: 'success',
            message: '退出登录!'
          });
        }).catch(() => {
                  
        });
    },
    toLogin() {
      this.$router.push("/login");
    },
    toRegister() {
      this.$router.push("/register");
    },
  },
};
</script>

<style scoped lang="less">
* {
  padding: 0;
  margin: 0;
}
.main,
body,
html {
  width: 100%;
  height: 100%;
}
@media screen and (max-width: 1000px) {
  .ipt {
    display: none;
  }
  .menu {
    display: none;
  }
}
.nav-context {
  width: 100%;
  padding: 5px 0;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .ative{
    border-bottom: 2px solid rgb(16, 115, 155);
  }
  a{
    box-sizing: border-box;
    color: black;
    padding: 3px 3px 3px 0px;
  }
}
.no {
  display: none;
}
.myself a {
  text-decoration: none;
}
.el-header {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  background-image: radial-gradient(#abfafa, #320cdf);
  border-bottom: 1px solid #c5c4b6;
}
.tool {
  width: 18%;
  font-size: 15px;
}
.tool * {
  margin-left: 10px;
  color: rgb(99, 93, 93);
}
.Logined {
  display: none;
}
.logo {
  width: auto;
}
.logo img {
  height: 10vh;
}
/* 
img {
  height: 60px;
} */
#search_box {
  width: 201px;
  height: 31px;
  background: url(//img.jbzj.com/demoimg/200912/bg_search_box.gif);
}
#search_box #s {
  float: left;
  padding: 0;
  margin: 6px 0 0 6px;
  border: 0;
  width: 159px;
  background: none;
  font-size: 16px;
}
#search_box #go {
  float: right;
  margin: 3px 4px 0 0;
}
.search {
  width: 100%;
  position: relative;
  display: flex;
}

.searchTerm {
  width: 100%;
  border: 3px solid #7acdd8;
  border-right: none;
  padding: 5px;
  height: 20px;
  border-radius: 5px 0 0 5px;
  outline: none;
  color: #9DBFAF;
}

.searchTerm:focus{
  color: #000000;
}

.searchButton {
  width: 40px;
  height: 36px;
  border: 1px solid #76c4ce;
  background: #75c9d4;
  text-align: center;
  color: #fff;
  border-radius: 0 5px 5px 0;
  cursor: pointer;
  font-size: 20px;
}
</style>